<?php
namespace BP\Sys;

use BP\WF\Glo;

// require_once("java/io/BufferedReader.php");
// require_once("java/io/File.php");
// require_once("java/io/IOException.php");
// require_once("java/io/InputStream.php");
// require_once("java/io/InputStreamReader.php");
// require_once("java/util/Date.php");
// require_once("java/util/Hashtable.php");
// require_once("java/util/Properties.php");
// require_once("org/apache/commons/io/IOUtils.php");
use BP\DA\Cash;
use BP\DA\CashEntity;
use BP\DA\DBType;
use BP\DA\DataRow;
use BP\DA\DataType;
use BP\DA\DataSet;
use BP\DA\DataTable;
use BP\DA\Depositary;
use BP\DA\Log;
// require_once("BP/Difference/Handler/CommonUtils.php");
// require_once("BP/Tools/StringHelper.php");
class SystemConfig {
	protected static $_IsBSsystem;	// boolean
	protected static $_CS_AppSettings;	// Hashtable<String, Object>
	public static $_CashFailDateTime;	// Date
	protected static $_AppCenterDBDatabase;	// String
	public static $CS_DBConnctionDic;	// Hashtable<String, Object>
	public static function __staticinit() { // static class members
		self::$_IsBSsystem =  TRUE ;
		self::$_CS_AppSettings = NULL;
		self::$_CashFailDateTime = date('Y-m-d h:i:s');
		self::$_AppCenterDBDatabase = NULL;
	}
	public static function getFTPServerType () 
	{
	    
		return SystemConfig::getAppSettings()->get("FTPServerType");
	}
	public static function getFTPServerIP () 
	{
		return SystemConfig::getAppSettings()->get("FTPServerIP");
	}
	public static function getFTPUserNo () 
	{
		$str = SystemConfig::getAppSettings()->get("FTPUserNo");
		return $str;
	}
	public static function getFTPUserPassword () 
	{
		$str = SystemConfig::getAppSettings()->get("FTPUserPassword");
		return $str;
	}
	public static function getIsEnableAthEncrypt () 
	{
		$isEnableAthEncryptObj = SystemConfig::getAppSettings()->get("IsEnableAthEncrypt");
		if (($isEnableAthEncryptObj == NULL))
		{
			return  FALSE ;
		}
		$IsEnableAthEncrypt = $isEnableAthEncryptObj;
		if (($DataType->IsNullOrEmpty($IsEnableAthEncrypt) ==  TRUE ))
			return  FALSE ;
		if (SystemConfig::getAppSettings()->get("IsEnableAthEncrypt") == "1")
			return  TRUE ;
		return  FALSE ;
	}
	public static function getIsUploadFileToFTP () 
	{
		$IsUploadFileToFTP = SystemConfig::getAppSettings()->get("IsUploadFileToFTP");
		if (($DataType->IsNullOrEmpty($IsUploadFileToFTP) ==  TRUE ))
			return  FALSE ;
		if (SystemConfig::getAppSettings()->get("IsUploadFileToFTP") == "1")
			return  TRUE ;
		return  FALSE ;
	}
	public static function getAttachWebSite () 
	{
		return SystemConfig::getAppSettings()->get("AttachWebSite");
	}
	public static function getOSModel () 
	{
// 		return OSModel->forValue(SystemConfig::GetValByKeyInt("OSModel", 0));
	}
	public static function getOSDBSrc () 
	{
// 		return OSDBSrc->forValue(SystemConfig::GetValByKeyInt("OSDBSrc", 0));
	}
	
	public static function GetConfigXmlEns ($key, $ensName) // [String key, String ensName]
	{
		try 
		{
			$tempVar = Cash::GetObj("TConfigEns", Depositary::Application);
			$dt = (( (($tempVar instanceof DataTable)) ? $tempVar : NULL ));
			if (($dt == NULL))
			{
				$ds = new DataSet("dss");
				$ds->readXml((SystemConfig::getPathOfXML() . "Ens/ConfigEns.xml"));
				$dt = $ds->Tables->get(0);
				Cash::AddObj("TConfigEns", Depositary::Application, $dt);
			}
			foreach ($dt->Rows as $dr) 			{
				if (($dr->getValue("Key")->equals($key) && $dr->getValue("For")->equals($ensName)))
				{
					return ( (($dr->getValue("Val") == NULL)) ? "" : $dr->getValue("Val") );
				}
			}
		}
		catch (\Exception $ex)
		{
			$ex->printStackTrace();
		}
		return NULL;
	}
	public static function getVer () 
	{
		try 
		{
			return SystemConfig::getAppSettings()->get("Ver");
		}
		catch (\Exception $e)
		{
			return "1.0.0";
		}
	}
	public static function getTouchWay () 
	{
		try 
		{
			return SystemConfig::getAppSettings()->get("TouchWay");
		}
		catch (\Exception $e)
		{
			return ((SystemConfig::getCustomerTel() . " 地址:") . SystemConfig::getCustomerAddr());
		}
	}
	public static function getCopyRight () 
	{
		try 
		{
			return SystemConfig::getAppSettings()->get("CopyRight");
		}
		catch (\Exception $e)
		{
			return ("版权�?有@" . SystemConfig::getCustomerName());
		}
	}
	public static function getCompanyID () 
	{
		$s = SystemConfig::getAppSettings()->get("CompanyID");
		if (is_null($s) || $s == '')
		{
			return "CCFlow";
		}
		return $s;
	}
	public static function getDeveloperName () 
	{
		return SystemConfig::getAppSettings()->get("DeveloperName");
	}
	public static function getDeveloperShortName () 
	{
		return SystemConfig::getAppSettings()->get("DeveloperShortName");
	}
	public static function getDeveloperTel () 
	{
		return SystemConfig::getAppSettings()->get("DeveloperTel");
	}
	public static function getDeveloperAddr () 
	{
		return SystemConfig::getAppSettings()->get("DeveloperAddr");
	}
	public static function getSysLanguage () 
	{
		return "CH";
	}
	public static function getCS_AppSettings () 
	{
	    if (((self::$_CS_AppSettings == NULL) || (sizeof(self::$_CS_AppSettings) == 0)))
		{
			try 
			{
				self::$_CS_AppSettings = [];// new Hashtable();
				$props = [];// new Properties();
				$is = NULL;
				try 
				{
// 					$is = $BP->Difference->Helper->loadResource();
// 					$bf = new BufferedReader(new InputStreamReader($is, "UTF-8"));
// 					$props->load($bf);
                    
                    $config = require __DIR__ . '/../../../application/config.php';
                    $database = require __DIR__ . '/../../../application/database.php';
                    $props = $config['ccflow'];
                    //设置ccflow参数
                    $props['AppCenterDBType'] = $database['type'];
                    $props['AppCenterDBDatabase'] = $database['database'];
                    $props['JflowUser'] = $database['username'];
                    $props['JflowPassword'] = $database['password'];
                    
                    $props['database'] = $database;
                    self::$_CS_AppSettings = $props;
				}catch (\Exception $e){
				    $e->getMessage();
				}
// 				finally {
// 				{
// 					$IOUtils->closeQuietly($is);
// 				}
// 				}
// 				self::$_CS_AppSettings = $props;
			}
			catch (\Exception $e)
			{
				throw new \RuntimeException("读取配置文件失败", $e);
			}
		}
		return self::$_CS_AppSettings;
	}
	public static function getAppSettings () 
	{
		return SystemConfig::getCS_AppSettings();
	}
	public static function getPhysicalApplicationPath () 
	{
		return "D:\\JJFlow\\trunk\\JJFlow\\";
	}
	public static function getPathOfUsersFiles () 
	{
		return "/Data/Files/";
	}
	public static function getPathOfTemp () 
	{
		return (SystemConfig::getPathOfDataUser() . "Temp");
	}
	public static function getPathOfWorkDir () 
	{
		return "D:/JJFlow/trunk/";
	}
	public static function getPathOfFDB () 
	{
		return (SystemConfig::getPathOfWebApp() . "/DataUser/FDB/");
	}
	public static function getPathOfData () 
	{
		Log::DebugWriteInfo(((((SystemConfig::getPathOfWebApp() . SystemConfig::getAppSettings()->get("DataDirPath")) . $File->separator) . "Data") . $File->separator));
		return ((((SystemConfig::getPathOfWebApp() . SystemConfig::getAppSettings()->get("DataDirPath")) . $File->separator) . "Data") . $File->separator);
	}
	public static function getPathOfDataUser () 
	{
		return ((SystemConfig::getPathOfWebApp() . SystemConfig::getAppSettings()->get("DataUserDirPath")) . "DataUser/");
	}
	public static function getPathOfXML () 
	{
		return ((SystemConfig::getPathOfWebApp() . SystemConfig::getAppSettings()->get("DataDirPath")) . "/Data/XML/");
	}
	public static function getPathOfAppUpdate () 
	{
		return ((SystemConfig::getPathOfWebApp() . SystemConfig::getAppSettings()->get("DataDirPath")) . "/Data/AppUpdate/");
	}
	public static function getPathOfCyclostyleFile () 
	{
		return (SystemConfig::getPathOfWebApp() . "DataUser/CyclostyleFile/");
	}
	public static function getAppName () 
	{
		return "JJFlow";
	}
	public static function getCCFlowAppPath () 
	{
		if ((SystemConfig::getAppSettings()->get("DataUserDirPath") != NULL))
		{
			return (SystemConfig::getPathOfWebApp() . SystemConfig::getAppSettings()->get("DataUserDirPath"));
		}
		return SystemConfig::getPathOfWebApp();
	}
	public static function getRunOnPlant () 
	{
		$str = SystemConfig::getAppSettings()->get("RunOnPlant");
		if (($str . NULL))
		{
			return "BP";
		}
		return $str;
	}
	public static function getCCFlowWebPath () 
	{
		return $BP->WF->Glo->getCCFlowAppPath();
	}
	public static function getPathOfWebApp () 
	{
		if (SystemConfig::getIsBSsystem())
		{
			if (((Glo::getRequest() == NULL) || (Glo::getRequest()->getSession() == NULL)))
			{
				return ($BP->WF->Glo->getHostURL() . "/");
			}
			else
			{
				return (Glo::getRequest()->getSession()->getServletContext()->getRealPath("") . "/");
			}
		}
		else
		{
			return "";
		}
	}
	public static function getIsBSsystem () 
	{
		return SystemConfig::GetValByKeyBoolen("IsBSsystem",  TRUE );
	}
	public static function setIsBSsystem ($value) // [boolean value]
	{
		SystemConfig::$_IsBSsystem = $value;
	}
	public static function getIsCSsystem () 
	{
		return !SystemConfig::getIsBSsystem();
	}
	public static function getSysNo () 
	{
		return SystemConfig::getAppSettings()->get("SysNo");
	}
	public static function getSysName () 
	{
		$s = SystemConfig::getAppSettings()->get("SysName");
		if (($s . NULL))
		{
			$s = "请在web.propertoes中配置SysName名称";
		}
		return $s;
	}
	public static function getOrderWay () 
	{
		return SystemConfig::getAppSettings()->get("OrderWay");
	}
	public static function getPageSize () 
	{
		try 
		{
			return $Integer->parseInt(SystemConfig::getAppSettings()->get("PageSize"));
		}
		catch (\Exception $e)
		{
			return 99999;
		}
	}
	public static function getMaxDDLNum () 
	{
		try 
		{
			return $Integer->parseInt(SystemConfig::getAppSettings()->get("MaxDDLNum"));
		}
		catch (\Exception $e)
		{
			return 50;
		}
	}
	public static function getPageSpan () 
	{
		try 
		{
			return $Integer->parseInt(SystemConfig::getAppSettings()->get("PageSpan"));
		}
		catch (\Exception $e)
		{
			return 20;
		}
	}
	public static function getPageOfAfterAuthorizeLogin () 
	{
		return SystemConfig::getAppSettings()->get("PageOfAfterAuthorizeLogin");
	}
	public static function getPageOfLostSession () 
	{
		return SystemConfig::getAppSettings()->get("PageOfLostSession");
	}
	public static function getPathOfLog () 
	{
		return (SystemConfig::getPathOfWebApp() . "/DataUser/Log/");
	}
	public static function getTopNum () 
	{
		try 
		{
			return $Integer->parseInt(SystemConfig::getAppSettings()->get("TopNum"));
		}
		catch (\Exception $e)
		{
			return 99999;
		}
	}
	public static function getServiceTel () 
	{
		return SystemConfig::getAppSettings()->get("ServiceTel");
	}
	public static function getServiceMail () 
	{
		return SystemConfig::getAppSettings()->get("ServiceMail");
	}
	public static function getThirdPartySoftWareKey () 
	{
		return SystemConfig::getAppSettings()->get("ThirdPartySoftWareKey");
	}
	public static function getIsEnableNull () 
	{
		if (SystemConfig::getAppSettings()->get("IsEnableNull")->equals("1"))
		{
			return  TRUE ;
		}
		else
		{
			return  FALSE ;
		}
	}
	public static function getIsDebug () 
	{
		if (SystemConfig::getAppSettings()["IsDebug"] == "1")
		{
			return  TRUE ;
		}
		else
		{
			return  FALSE ;
		}
	}
	public static function getIsOpenSQLCheck () 
	{
		if (SystemConfig::getAppSettings()->get("IsOpenSQLCheck")->equals("0"))
		{
			return  FALSE ;
		}
		else
		{
			return  TRUE ;
		}
	}
	public static function getIsMultiSys () 
	{
		if (SystemConfig::getAppSettings()->get("IsMultiSys")->equals("1"))
		{
			return  TRUE ;
		}
		else
		{
			return  FALSE ;
		}
	}
	public static function getIsMultiThread_del () 
	{
		if (SystemConfig::getAppSettings()->get("IsMultiThread")->equals("1"))
		{
			return  TRUE ;
		}
		else
		{
			return  FALSE ;
		}
	}
	public static function getIsMultiLanguageSys () 
	{
		if (SystemConfig::getAppSettings()->get("IsMultiLanguageSys")->equals("1"))
		{
			return  TRUE ;
		}
		else
		{
			return  FALSE ;
		}
	}
	protected static function getCashFail () 
	{
		try 
		{
			return $Integer->parseInt(SystemConfig::getAppSettings()->get("CashFail"));
		}
		catch (\Exception $e)
		{
			return 0;
		}
	}
	public static function getIsTempCashFail () 
	{
		return  TRUE ;
	}
	public static function getCustomerNo () 
	{
		return SystemConfig::getAppSettings()->get("CustomerNo");
	}
	public static function getCustomerName () 
	{
		return SystemConfig::getAppSettings()->get("CustomerName");
	}
	public static function getCustomerURL () 
	{
		return SystemConfig::getAppSettings()->get("CustomerURL");
	}
	public static function getCustomerShortName () 
	{
		return SystemConfig::getAppSettings()->get("CustomerShortName");
	}
	public static function getCustomerAddr () 
	{
		return SystemConfig::getAppSettings()->get("CustomerAddr");
	}
	public static function getCustomerTel () 
	{
		return SystemConfig::getAppSettings()->get("CustomerTel");
	}
	public static function getWX_CorpID () 
	{
		return SystemConfig::getAppSettings()->get("CorpID");
	}
	public static function getWX_AppSecret () 
	{
		return SystemConfig::getAppSettings()->get("AppSecret");
	}
	public static function getWX_WeiXinToken () 
	{
		return SystemConfig::getAppSettings()->get("WeiXinToken");
	}
	public static function getWX_EncodingAESKey () 
	{
		return SystemConfig::getAppSettings()->get("EncodingAESKey");
	}
	public static function getWeiXin_AgentWelCom () 
	{
		return SystemConfig::GetValByKeyBoolen("WeiXin_AgentWelCom",  FALSE );
	}
	public static function getWX_AgentID () 
	{
		return SystemConfig::getAppSettings()->get("AgentID");
	}
	public static function getWX_MessageUrl () 
	{
		return SystemConfig::getAppSettings()->get("WeiXin_MessageUrl");
	}
	public static function getDing_CorpID () 
	{
		return SystemConfig::getAppSettings()->get("Ding_CorpID");
	}
	public static function getDing_CorpSecret () 
	{
		return SystemConfig::getAppSettings()->get("Ding_CorpSecret");
	}
	public static function getDing_SSOsecret () 
	{
		return SystemConfig::getAppSettings()->get("Ding_SSOsecret");
	}
	public static function getDing_MessageUrl () 
	{
		return SystemConfig::getAppSettings()->get("Ding_MessageUrl");
	}
	public static function getDing_AgentID () 
	{
		return SystemConfig::getAppSettings()->get("Ding_AgentID");
	}
	public static function GetValByKey ($key, $isNullas) // [String key, String isNullas]
	{
		if ((SystemConfig::getAppSettings()->containsKey($key) ==  FALSE ))
			return $isNullas;
		$s = SystemConfig::getAppSettings()->get($key);
		if (($s == NULL))
		{
			$s = $isNullas;
		}
		return $s;
	}
	public static function GetValByKeyBoolen ($key, $isNullas) // [String key, boolean isNullas]
	{
		if ((SystemConfig::getAppSettings()->containsKey($key) ==  FALSE ))
			return $isNullas;
		$s = SystemConfig::getAppSettings()->get($key);
		if (($s . NULL))
			return $isNullas;
		if (($s . NULL))
			return $isNullas;
		if ($s->equals("1"))
			return  TRUE ;
		return  FALSE ;
	}
	public static function GetValByKeyInt ($key, $isNullas) // [String key, int isNullas]
	{
		if ((SystemConfig::getAppSettings()->containsKey($key) ==  FALSE ))
			return $isNullas;
		$s = SystemConfig::getAppSettings()->get($key);
		if (($s == NULL))
		{
			return $isNullas;
		}
		return $Integer->parseInt($s);
	}
	public static function GetValByKeyFloat ($key, $isNullas) // [String key, int isNullas]
	{
		if ((SystemConfig::getAppSettings()->containsKey($key) ==  FALSE ))
			return $isNullas;
		$s = SystemConfig::getAppSettings()->get($key);
		if (($s == NULL))
		{
			return $isNullas;
		}
		return $Float->parseFloat($s);
	}
	public static function getAppCenterDSN () 
	{
		$dsn = SystemConfig::getAppSettings()->get("AppCenterDSN");
		return $dsn;
	}
	public static function getUser () 
	{
		if (SystemConfig::getCustomerNo()->equals("BWDA"))
		{
			$user = SystemConfig::getAppSettings()->get("JflowUser.encryption");
			$user = Glo::String_JieMi($user);
			return $user;
		}
		return SystemConfig::getAppSettings()->get("JflowUser");
	}
	public static function getPassword () 
	{
		if (SystemConfig::getCustomerNo()->equals("BWDA"))
		{
			$user = SystemConfig::getAppSettings()->get("JflowPassword.encryption");
			$user = Glo::String_JieMi($user);
			return $user;
		}
		return SystemConfig::getAppSettings()->get("JflowPassword");
	}
	public static function setAppCenterDSN ($value) // [String value]
	{
		SystemConfig::getAppSettings()->put("AppCenterDSN", $value);
	}
	public static function getAppCenterDBType () 
	{
	    $appSettings = SystemConfig::getAppSettings();
		$jdbcType = $appSettings["AppCenterDBType"];
		if (($jdbcType != NULL))
		{
			$dbType = $jdbcType;
// 			if ( ($dbType->equalsIgnoreCase("MSMSSQL") || $dbType->equalsIgnoreCase("MSSQL")))
            if ( strcasecmp($dbType, "MSMSSQL") == 0 || strcasecmp($dbType, "MSSQL") == 0)
			{
			    return  DBType::MSSQL;
			}
			else
				if (strcasecmp($dbType, "Oracle") == 0)
				{
					return DBType::Oracle;
				}
				else
				    if (strcasecmp($dbType, "MySQL") == 0)
					{
						return DBType::MySQL;
					}
		}
		throw new \RuntimeException("位置的数据库类型，请配置AppCenterDBType属�?��??");
	}
	public static function getAppCenterDBVarStr () 
	{
		switch (SystemConfig::getAppCenterDBType()) {
			case $MSSQL:
				return ":";
			case $Oracle:
				return ":";
			case $Informix:
				return "?";
			case $MySQL:
				return ":";
			default:
				return "";
		}
	}
	public static function getAppCenterDBLengthStr () 
	{
		switch (SystemConfig::getAppCenterDBType()) {
			case $Oracle:
				return "Length";
			case $MSSQL:
				return "LEN";
			case $Informix:
				return "Length";
			case $Access:
				return "Length";
			default:
				return "Length";
		}
	}
	public static function getAppCenterDBSubstringStr () 
	{
		switch (SystemConfig::getAppCenterDBType()) {
			case $Oracle:
				return "substr";
			case $MSSQL:
				return "substring";
			case $Informix:
				return "MySubString";
			case $Access:
				return "Mid";
			default:
				return "substring";
		}
	}
	public static function getAppCenterDBDatabase () 
	{
		if ((self::$_AppCenterDBDatabase . NULL))
		{
			self::$_AppCenterDBDatabase = SystemConfig::getAppSettings()->get("AppCenterDBDatabase");
		}
		return self::$_AppCenterDBDatabase;
	}
	public static function getAppCenterDBAddStringStr () 
	{
		switch (SystemConfig::getAppCenterDBType()) {
			case $Oracle:
			case $MySQL:
			case $Informix:
				return "||";
			default:
				return "+";
		}
	}
	public static function getAppSavePath () 
	{
		$savePath = SystemConfig::getAppSettings()->get("SavaPath");
		return $savePath;
	}
	public static function DoClearCash_del () 
	{
		SystemConfig::DoClearCash();
	}
	public static function DoClearCash () 
	{
		Cash::getMap_Cash()->clear();
		Cash::getSQL_Cash()->clear();
		Cash::getEnsData_Cash()->clear();
		Cash::getEnsData_Cash_Ext()->clear();
		Cash::getBS_Cash()->clear();
		Cash::getBill_Cash()->clear();
		CashEntity::getDCash()->clear();
	}
	public static function getIsEnableCCIM () 
	{
		if ("1" /* from: "1".equals(getAppSettings().get("IsEnableCCIM")) */)
		{
			return  TRUE ;
		}
		else
		{
			return  FALSE ;
		}
	}
	public static function getIsEnablePasswordEncryption () 
	{
		$s = (( ((SystemConfig::getAppSettings()->get("IsEnablePasswordEncryption") instanceof String)) ? SystemConfig::getAppSettings()->get("IsEnablePasswordEncryption") : NULL ));
		if ((($s . NULL) . $s->equals("0")))
		{
			return  FALSE ;
		}
		return  TRUE ;
	}
	public static function getHostURL () 
	{
		if (($DataType->IsNullOrEmpty(SystemConfig::getAppSettings()->get("HostURL")) ==  FALSE ))
		{
			return SystemConfig::getAppSettings()->get("HostURL");
		}
		return SystemConfig::getHostURLOfBS();
	}
	public static function getHostURLOfBS () 
	{
		$url = ((((("http://" . $CommonUtils->getRequest()->getServerName()) . ":") . $CommonUtils->getRequest()->getServerPort()) . "/") . $CommonUtils->getRequest()->getContextPath());
		return $url;
	}
	public static function getMobileURL () 
	{
		if (($DataType->IsNullOrEmpty(SystemConfig::getAppSettings()->get("MobileURL")) ==  FALSE ))
		{
			return SystemConfig::getAppSettings()->get("MobileURL");
		}
		return SystemConfig::getHostURLOfBS();
	}
	public static function getIsMultilingual () 
	{
		if (SystemConfig::getAppSettings()->get("IsMultilingual")->equals("1"))
			return  TRUE ;
		return  FALSE ;
	}
	public static function getLangue () 
	{
		$str = SystemConfig::getAppSettings()->get("Langue");
		if ($DataType->IsNullOrEmpty($str))
			return "CN";
		return $str;
	}
}
SystemConfig::__staticinit(); // initialize static vars for this class on load
?>
